{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "# Joy Ride - Part 3: Parallel Parking\n",
    "In this section you will write a function that implements the correct sequence of steps required to parallel park a vehicle.\n",
    "\n",
    "**Note** for this segment the vehicle's maximum speed has been set to just over 4 mph. This should make parking a little easier.\n",
    "\n",
    "![](https://upload.wikimedia.org/wikipedia/commons/2/26/ParallelParkingAnimation.gif)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<button id=\"launcher\">Launch Car Simulator</button>\n",
       "<script src=\"setupLauncher.js\"></script>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "%%HTML\n",
    "<button id=\"launcher\">Launch Car Simulator</button>\n",
    "<script src=\"setupLauncher.js\"></script>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# CODE CELL\n",
    "#\n",
    "# Write the park function so that it actually parks your vehicle.\n",
    "\n",
    "from Car import Car\n",
    "import time\n",
    "\n",
    "def park(car):\n",
    "    # TODO: Fix this function!\n",
    "    #  currently it just drives back and forth\n",
    "    #  Note that the allowed steering angles are\n",
    "    #  between -25.0 and 25.0 degrees and the \n",
    "    #  allowed values for gas are between -1.0 and 1.0\n",
    "    \n",
    "    #  back up with 25.0 right angles for 3.1 seconds\n",
    "    car.steer(25.0)\n",
    "    car.gas(-0.5)\n",
    "    time.sleep(2.9) # note how time.sleep works\n",
    "    \n",
    "    # back up for 2.7 seconds to keep the car parall  park \n",
    "    car.steer(-25.0)\n",
    "    car.gas(-0.5)\n",
    "    time.sleep(2.6) \n",
    "    \n",
    "    \n",
    "    # slow down the speed \n",
    "    car.steer(0.0)\n",
    "    car.gas(0.1)\n",
    "    time.sleep(1.8)\n",
    "    \n",
    "    car.steer(0.0)\n",
    "    car.gas(-0.02)\n",
    "    time.sleep(1.5)\n",
    "    \n",
    "    # stop the car \n",
    "    car.steer(0.0)\n",
    "    car.gas(0.000000002)\n",
    "    time.sleep(600.0)\n",
    "    \n",
    "    \n",
    "\n",
    "car = Car()\n",
    "park(car)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Submitting this Project!\n",
    "Your parallel park function is \"correct\" when:\n",
    "\n",
    "1. Your car doesn't hit any other cars.\n",
    "2. Your car stops completely inside of the right lane.\n",
    "\n",
    "Once you've got it working, it's time to submit. Submit by pressing the `SUBMIT` button at the lower right corner of this page."
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
